require('./PageSingleproject.styl');

const reactMixin = require('react-mixin');
const Actions = require('./actions');
const Store = require('./store');
import { Control } from 'react-keeper';
const ui = require('clientConfig/util/jsapi/ui');
const PendingList = require('components/pendinglist')
const Search = require('components/search')
const WithRefresh = require('components/withrefresh');
let listData = []
let keyWord = ''
const ListWithSingleproject = WithRefresh(
    PendingList,
    (pageNum, props, success, error) => {
        Actions.fetchList(pageNum, props, success, error)
    }
);
class Singleproject extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            listData: [],
            currentType: 0 //0 搜索项目名称， 1 搜索项目编号
        };
        this.searchRange = ["项目名称", "项目编号"]
        this.handleChangeSearchType = this.handleChangeSearchType.bind(this);
    }

    onsearch(keyword) {
        this.setState({
            keyword: keyword
        }, () => {
            if (keyword!= undefined) {
                var props = {
                    pageSize: 10,
                }
                if (!!this.state.currentType) {//全为数字的是项目编号
                    props.proj_num = keyword
                    Actions.fetchList(0, props)
                } else {
                    props.proj_name = keyword
                    Actions.fetchList(0, props)
                }
            }
        })
    }
    onexit() {//退出搜索
        this.setState({
            keyword: "",
            listData: []
        })
    }

    handleChangeSearchType(currentType) {
        this.setState({ currentType })
    }

    render() {
        let t = this;
        if (Control.state)
            var origin = Control.state.origin;
        else
            var origin = "";
        return (
            <div className="singleproject">
                <Search
                    onsearch={this.onsearch.bind(this)}
                    searchRange={this.searchRange}
                    data={this.state.listData}
                    origin={origin}
                    onExit={this.onexit.bind(this)}
                    classname={true}
                    currentType={t.state.currentType}
                    handleChangeSearchType={this.handleChangeSearchType}
                />
                <ListWithSingleproject className="workplan-manage" origin={origin} />
            </div>
        );
    }

    componentWillMount() {
        ui.setTitle({ title: "项目列表" });
    }

    componentDidMount() { }

    componentWillReceiveProps(nextProps) { }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) { }

    componentDidUpdate(prevProps, prevState) { }

    componentWillUnmount() { }
}

reactMixin.onClass(Singleproject, Reflux.connect(Store));

module.exports = Singleproject;
